package com.cskaoyan.controller.wx;


import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.po.MarketAddress;
import com.cskaoyan.bean.wx.address.WxAddressDateVo;
import com.cskaoyan.config.exception.LoginAuthenException;
import com.cskaoyan.service.wx.WxAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("wx/address")
public class WxAddressController {

    @Autowired
    WxAddressService wxAddressService;


    @GetMapping("list")
    public BaseRespVo list(){

        WxAddressDateVo wxAddressDateVo = wxAddressService.queryAll();

        BaseRespVo<Object> baseRespVo = new BaseRespVo<>();
        baseRespVo.setErrno(0);
        baseRespVo.setErrmsg("成功");
        baseRespVo.setData(wxAddressDateVo);
        return baseRespVo;
    }

    @PostMapping("save")
    public BaseRespVo save(@RequestBody() MarketAddress marketAddress) throws LoginAuthenException {

        int id = wxAddressService.inset(marketAddress);

        BaseRespVo<Object> baseRespVo = new BaseRespVo<>();
        baseRespVo.setErrno(0);
        baseRespVo.setErrmsg("成功");
        baseRespVo.setData(id);
        return baseRespVo;

    }

    @PostMapping("delete")
    public BaseRespVo delete(@RequestBody() MarketAddress marketAddress){

        wxAddressService.delete(marketAddress);

        return BaseRespVo.ok();
    }

    @GetMapping("detail")
    public BaseRespVo detail(Integer id){

        MarketAddress marketAddress = wxAddressService.select(id);

        return BaseRespVo.ok(marketAddress);
    }

}
